<?php

namespace app\v1\logic;

use app\v1\model\AdminCity;
use app\v1\model\MiniOrder;

class MiniOrderLogic
{
    public MiniOrder $model;

    public function __construct()
    {
        $this->model = new MiniOrder();
    }

    /**
     * 获取订单列表
     * @return array
     */
    public function getList($param, $userId): ?array
    {
        $page = [
            'page' => $param['page'] ?? 1,
            'list_rows' => $param['pageSize'] ?? 10
        ];
        $data_list = $this->model->where('create_user_id', $userId)->order('create_time desc')->paginate($page)->toArray();
        foreach ($data_list['data'] as $k => $v) {
            if ($v['lawyer_id']) {
                $lawyerInfo = (new MiniLawyerLogic())->model->find($v['lawyer_id'])->toArray();
                if ($lawyerInfo['area']) {
                    $lawyerInfo['area'] = (new AdminCity())->getCityName($lawyerInfo['area']);
                }
                $v['lawyer_id_info'] = $lawyerInfo;
            }
            if ($v['pay_data']) {
                $v['pay_data'] = json_decode($v['pay_data'], true);
            }

            $data_list['data'][$k] = $v;
        }
        return $data_list;
    }
}